package com.smdk.dsminio.request;
import com.alibaba.fastjson.JSONObject;
import com.smdk.dsminio.utils.CookieUtil;
import com.smdk.dsminio.utils.GetIPAddress;
import com.smdk.dsminio.utils.JwtUtil;
import com.smdk.dsminio.vo.UserInfoVO;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * Created by Administrator on 2017/8/17/017.
 */
public class OnLlineUserInfo extends BaseUtils {
    /**
     * 获取用户信息(token验证)
     *
     * @param
     * @return
     */
    public static UserInfoVO getUserInfo(HttpServletRequest request) {
        String accessToken = CookieUtil.getCookieValue(request, "accessToken", true);
        if (accessToken != null) {
            Map<String, String> map = JwtUtil.decode(accessToken, GetIPAddress.getIp(request));
            UserInfoVO userInfo = JSONObject.parseObject(map.get("userInfo"), UserInfoVO.class);
            return userInfo;
        } else {
            return null;
        }
    }
}
